package com.feihao.zhou.controller;

import com.feihao.zhou.domain.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@Controller
public class UserController {

    @RequestMapping("/say")
    public String say(){
        System.out.println("say hello!");
        return "success.jsp" ;
    }

    @RequestMapping("/test01")
    public String test01(String name,int age){   //测试请求参数接收
        System.out.println(name+"," + age);
        return "springMVC.jsp";
    }


    @RequestMapping("/test03")
    public String test02(String[] str){
        for (String s : str) {
            System.out.println(s);
        }
        return "success.jsp";
    }


    @RequestMapping("/test04")
    public String test04(@DateTimeFormat(pattern = "yyyyy-MM-dd") Date date){
        System.out.println(date);
        return "success.jsp";
    }


//    ---------------跳转页面：----------------
    @RequestMapping("/test05")
    public ModelAndView test05(String name,ModelAndView modelAndView){
        String str = "eeee+测试5";
        System.out.println(name);
        modelAndView.addObject("str",str);
        modelAndView.setViewName("forward:/success.jsp");
        return modelAndView;
    }



    //跳转携带json:
    @RequestMapping("/test06")
    @ResponseBody
    public User test06(ModelAndView modelAndView){
        User user = new User("张三",28,"湖南长沙");
        modelAndView.addObject("user",user);
        modelAndView.setViewName("/success.jsp");
        return user;
    }
}
